<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <?= $show_code; ?>
        <title><?php echo $this->config->item('title_page'); ?></title>
    </head>
    <script>
        $(document).ready(function() {
            //Event Combobox Model

            $('#cmbBrand').change(function() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>truck/add_truck/get_model",
                    data: {id: $('#cmbBrand').val()},
                    dataType: "json",
                    success: function(data) {
                        $("#cmbModel").find("option").remove();
                        if (data.length > 0) {
                            var opt = $('<option />');
                            opt.val("");
                            opt.text(data.list_model[""]);
                            $('#cmbModel').append(opt);
                            $.each(data.list_model, function(key, val) {
                                if (key !== "") {
                                    var opt = $('<option />');
                                    opt.val(key);
                                    opt.text(val);
                                    $('#cmbModel').append(opt);
                                }
                            });
                        }
                    }
                });
            });
        });
    </script>
    <body>
        <div class="panel panel-default body-contain">
            <div class="panel-heading"><span class="icon-g-truck"></span>
                <strong> การจัดการรถบรรทุก (Truck Management)</strong>
            </div>
            <div class="panel-body">
                <?php $this->load->view('contains/menu_module_bar'); ?>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="panel panel-default">
                            <!-- Default panel contents -->
                            <div class="panel-heading"><strong>ค้นหาข้อมูลรถบรรทุก</strong></div>
                            <?php echo form_open('truck/home/search', 'class="form-inline"  method="post"') ?>
                            <?php echo form_hidden('action', 'search') ?>
                            <div class="panel-body text-center" >
                                <div class="form-group margin-right">
                                    <label class="control-label">ทะเบียน</label>
                                    <?= $txt_license_code; ?>
                                </div>
                                <div class="form-group margin-right">
                                    <label class="control-label">ยี่ห้อ</label>
                                    <?= $cmb_brand; ?>
                                </div>
                                <div class="form-group margin-right">
                                    <label class="control-label">รุ่น</label>
                                    <?= $cmb_model; ?>
                                </div>
                                <div class="form-group margin-right">
                                    <label class="control-label">หมายเลขเครื่อง</label>
                                    <?= $txt_moter_code; ?>
                                </div>
                            </div>
                            <div class="text-center margin-bottom">
                                <button type="submit" class="btn btn-default">
                                    <span class="glyphicon glyphicon-search"></span>
                                    <strong>ค้นหา</strong>
                                </button>
                                <button type="button" class="btn btn-default" onclick="location.href = '<?= base_url(); ?>truck/home'">
                                    <span class="icon-g-cleaning"></span>
                                    <strong>ล้างค่า</strong>
                                </button>
                            </div>
                            <?php echo form_close(); ?>
                            <ul class="nav nav-tabs"></ul>
                            <div class="pull-right">
                                <!--<button class="btn btn-success"><span class="glyphicon glyphicon-list-alt"></span> <strong>ประวัติการแก้ไข</strong></button>-->
                                <button class="btn btn-primary position-search-btn" onclick="location.href = '<?= base_url(); ?>truck/add_truck'"><span class="glyphicon glyphicon-file"></span> <strong>เพิ่มข้อมูล</strong></button>
                            </div>

                            <!-- Table -->
                            <table class="table table-condensed table-hover table-bordered imagetable">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>ทะเบียน</th>
                                        <th>ยี่ห้อ</th>
                                        <th>รุ่น</th>
                                        <th>หมายเลขเครื่อง</th>
                                        <th>การจัดการ</th>
                                    </tr>
                                </thead>
                                <?php
                                $utility = new Config_utility();
                                $num_list = $num_list;
                                foreach ($result_list as $list) {
                                    if ($list->is_deleted != 'Y') {
                                        ?>
                                        <tr>
                                            <td>
                                                <?= $num_list = $num_list + 1; ?>
                                            </td>
                                            <td>
                                                <?= $list->license_plate_code; ?>
                                            </td>
                                            <td>
                                                <?= $list->brand_name; ?>
                                            </td>
                                            <td>
                                                <?= $list->model_name; ?>
                                            </td>
                                            <td>
                                                <?= $list->moter_code; ?>
                                            </td>
                                            <td>
                                                <button class="btn btn-default btn-sm" onclick="location.href = '<?= base_url(); ?>truck/view_truck?id=<?= $list->truck_id ?>'">
                                                    <span class="glyphicon glyphicon-eye-open"></span>
                                                </button>
                                                <button class="btn btn-default btn-sm" onclick="location.href = '<?= base_url(); ?>truck/edit_truck?id=<?= $list->truck_id ?>'">
                                                    <span class="glyphicon glyphicon-edit"></span>
                                                </button>
                                                <button class="btn btn-danger btn-sm"  onclick="if (confirm('ยืนยันการลบรายการ?') === true) {
                                                                        location.href = '<?= base_url(); ?>truck/delete_truck?id=<?= $list->truck_id ?>'
                                                                    } else {
                                                                        return false;
                                                                    }">
                                                    <span class="glyphicon glyphicon-trash"></span>
                                                </button>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                }
                                ?>
                            </table>
                            <div class="panel-footer footprint-size">
                                <div class="pull-right">
                                    <?= $this->pagination->create_links(); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
